package chapter06

import java.util.Properties

import com.typesafe.config.{Config, ConfigFactory}
import org.apache.spark.sql.{DataFrame, SparkSession}

object HiveSourceApp {
  def main(args: Array[String]): Unit = {
    val spark: SparkSession = SparkSession.builder()
      .appName("HiveSourceApp")
      .master("local")
      .enableHiveSupport() //开启hive的支持
      .getOrCreate()

    //spark.table("myhive.pk").show()

    val config: Config = ConfigFactory.load()
    val driver: String = config.getString("db.default.driver")
    val url: String = config.getString("db.default.url")
    val user: String = config.getString("db.default.user")
    val password: String = config.getString("db.default.password")
    val database: String = config.getString("db.default.database")
    val table: String = config.getString("db.default.table")
    val sinkTable: String = config.getString("db.default.sink.table")

    val properties = new Properties()
    properties.put("user", user)
    properties.put("password", password)

    val jdbc2DF: DataFrame = spark.read
      .jdbc(url, s"$database.$table", properties)
    //jdbc2DF.show()

    jdbc2DF.write.saveAsTable("myhive.browser_start_hive")


    spark.stop()


  }
}
